package group.igfd.manager.biz.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import group.igfd.manager.biz.entity.CouponActivityEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import group.igfd.manager.biz.service.CouponActivityService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 活动表
 *
 * @author knight
 * @email sunlightcs@gmail.com
 * @date 2018-11-28 11:15:26
 */
@RestController
@RequestMapping("biz/couponActivity")
public class CouponActivityController {
    @Autowired
    private CouponActivityService couponActivityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("biz:couponActivity:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = couponActivityService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("biz:couponActivity:info")
    public R info(@PathVariable("id") Integer id){
			CouponActivityEntity couponActivity = couponActivityService.selectById(id);

        return R.ok().put("couponActivity", couponActivity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("biz:couponActivity:save")
    public R save(@RequestBody CouponActivityEntity couponActivityEntity){


        couponActivityEntity.setCreatedAt(new Date());
        couponActivityEntity.setUpdatedAt(new Date());

        couponActivityService.insert(couponActivityEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("biz:couponActivity:update")
    public R update(@RequestBody CouponActivityEntity couponActivity){
        couponActivity.setUpdatedAt(new Date());
        couponActivityService.updateById(couponActivity);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("biz:couponActivity:delete")
    public R delete(@RequestBody Integer[] ids){
			couponActivityService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
